﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI.HtmlControls;
using System.IO;

namespace WebSite
{
    public class upload
    {
        // Fields
        public string[] Resup = new string[] { "上传失败或指定的文件不存在", "文件不能大于2M，重新传图片！", "格式不对，限制上传（只允许gif,jpg,jpeg,bmp,zip,rar,doc,xls,pdf格式文件）！", "<font color=#ff0000>上传成功！</font>" };
        public string s = string.Empty;

        // Methods
        public string Up(HtmlInputFile File2, string Pa)
        {
            if (File2.PostedFile.ContentLength.ToString() == "0")
            {
                return "0";
            }
            string str = DateTime.Now.ToString().Replace("-", "").Replace(" ", "").Replace(":", "").Replace("/", "") + Path.GetExtension(File2.PostedFile.FileName);
            if ((File2.PostedFile.ContentLength / 0x400) > 0x800)
            {
                return "1";
            }
            string contentType = File2.PostedFile.ContentType;
            if (((!(contentType == "image/gif") && !(contentType == "image/pjpeg")) && (!(contentType == "application/octet-stream") && !(contentType == "application/x-zip-compressed"))) && ((!(contentType == "image/bmp") && !(contentType == "application/msword")) && ((!(contentType == "application/vnd.ms-excel") && !(contentType == "application/x-shockwave-flash")) && !(contentType == "application/pdf"))))
            {
                return "2";
            }
            File2.PostedFile.SaveAs(HttpContext.Current.Server.MapPath(Pa) + str);
            this.s = str;
            return "3";
        }

    }
}